package cn.otrue.patienthealthmanager.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import cn.otrue.patienthealthmanager.R;

public class CenterScoreAdapter extends BaseAdapter {
	private List<Map<String, String>> data;
	private LayoutInflater inflater;

	public CenterScoreAdapter(Context context, List<Map<String, String>> data) {
		inflater = LayoutInflater.from(context);
		this.data = data;
	}

	@Override
	public int getCount() {
		return data.size() > 0 ? data.size() : 0;
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		HolderView holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.center_score_item, null);
			holder = new HolderView();
			holder.tv_center_score_context = (TextView) convertView
					.findViewById(R.id.tv_center_score_context);
			holder.tv_center_score_score = (TextView) convertView
					.findViewById(R.id.tv_center_score_score);
			holder.tv_center_score_times = (TextView) convertView
					.findViewById(R.id.tv_center_score_times);
			convertView.setTag(holder);
		} else {
			holder = (HolderView) convertView.getTag();
		}
		holder.tv_center_score_context.setText(data.get(position).get("content"));
		holder.tv_center_score_score.setText(data.get(position).get("score"));
		holder.tv_center_score_times.setText(data.get(position).get("times"));
		return convertView;
	}

	class HolderView {
		TextView tv_center_score_context;
		TextView tv_center_score_score;
		TextView tv_center_score_times;
	}
}
